#include "config.h"
#include <QFile>
#include <QTextStream>

namespace Config {

void initAppPaths()
{
    QDir dir;
    QStringList paths = { BASE_PATH, LOG_PATH };
    for (const QString &path : paths) {
        if (!dir.exists(path)) {
            dir.mkpath(path);
            qDebug() << "创建目录:" << path;
        }
    }
}

QString currentTimestamp()
{
    return QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
}

void writeLog(const QString &msg)
{
    QString fileName = LOG_PATH + QDate::currentDate().toString("yyyyMMdd") + ".log";
    QFile file(fileName);
    if (file.open(QIODevice::Append | QIODevice::Text)) {
        QTextStream out(&file);
        out << currentTimestamp() << " - " << msg << "\n";
        file.close();
    }
    qDebug() << msg;
}
//当前工作目录
QString currentWorkDir()
{
    return QCoreApplication::applicationDirPath();
}

} // namespace Config
